package dota.entity;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import dota.ImageManager;
import dotaframework.utils.AgeFactory;
import dotaframework.utils.VisitorClassicForArmedUnit;
import dotaframework.utils.VisitorFunForArmedUnit;
import gameframework.base.Drawable;
import gameframework.base.DrawableImage;
import gameframework.game.GameEntity;
import gameframework.game.MoveBlocker;

public class Castle extends SoldierAbstract implements ArmedUnit, Drawable, MoveBlocker, GameEntity{

	protected static DrawableImage image = null;
	int x, y;
	public static final int SPRITE_SIZE = 32;
	private static final int HEALTHPOINTS = 50000;
	private static final int FORCE = 10;
	private MoveBlocker blocker;

	public Castle(int xx, int yy, String name) {
		super(name, HEALTHPOINTS, FORCE);
		initialHealthPoints = HEALTHPOINTS;
		if (image == null) {
			image = ImageManager.getImage(ImageManager.CASTLE);
		}
		x = xx;
		y = yy;
	}
	
	public void draw(Graphics g) {
		g.drawImage(image.getImage(), x, y, SPRITE_SIZE, SPRITE_SIZE, null);
		
		//Drawing life bar frame
		int barWidth = getBoundingBox().width;
		
		g.setColor(Color.BLACK);
		g.drawRect(x-10, y-10, barWidth+20, 5);
		
		
		float LifePercentage = getHealthPoints()/getInitialHealthPoints();

		//GREEN = high life, YELLOW = middle life, RED = low life
		if ( LifePercentage > 0.63 )
			g.setColor(Color.GREEN);
		else if ( LifePercentage > 0.33 )
			g.setColor(Color.YELLOW);
		else
			g.setColor(Color.RED);

		//Drawing life bar inside
		g.fillRect(x+1-10, y-9, (int) ((barWidth-1+20)*LifePercentage), 4);
	}

	public Point getPos() {
		return (new Point(x, y));
	}

	public Rectangle getBoundingBox() {
		return (new Rectangle(x, y, SPRITE_SIZE, SPRITE_SIZE));
	}

	@Override
	public void heal() {
		healthPoints = initialHealthPoints;
		
	}
	
	public void setBlocker(MoveBlocker moveBlocker) {
		blocker = moveBlocker;
	}

	public ArmedUnit getBlocker() {
		return (ArmedUnit) blocker;
	}

	@Override
	public AgeFactory getAge() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean addEquipment(String weaponType) {
		return false;
		// TODO Auto-generated method stub
		
	}

	@Override
	public void accept(VisitorClassicForArmedUnit v) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public <T> T accept(VisitorFunForArmedUnit<T> v) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void levelUp() {
		// TODO Auto-generated method stub
		
	}
}
